# 导包
from selenium.webdriver.common.by import By
from util_tools.basePage import BasePage
from time import sleep
import allure

class FlowPage(BasePage):
    url = '/flow.php'
    settle_button = (By.XPATH, '//*[@alt="checkout"]')
    continue_button = (By.XPATH, '//*[@alt="continue"]')
    country = (By.NAME, 'country')      
    province = (By.NAME, 'province')    
    city = (By.NAME, 'city')            
    district = (By.NAME, 'district')    
    consignee = (By.NAME, 'consignee')  
    address = (By.NAME, 'address')      
    tel = (By.NAME, 'tel')              
    email = (By.NAME, 'email')          
    submit = (By.NAME, 'Submit')
    shipping_radio = (By.NAME, 'shipping')
    payment_radio = (By.NAME, 'payment')
    submit_order = (By.XPATH, '//input[@type="image"]')

    def flow_failed(self):
        self.open_url(self.url)
        self.click(self.settle_button)

    def flow_success(self):
        self.open_url(self.url)
        allure.attach(self.url, '打开测试页面', attachment_type=allure.attachment_type.TEXT)
        self.click(self.settle_button)
        if self.is_element_present(self.country):
            self.selects(self.country, 1)
            self.selects(self.province, 2)
            self.selects(self.city, 3)
            self.selects(self.district, 4)
            self.send_keys(self.consignee, 'test张三')
            self.send_keys(self.address, '测试详细地址01号')
            self.send_keys(self.tel, '13111111111')
            self.send_keys(self.email, '123@qq.com')
            allure.attach(self.screenshots_png(), '配送信息输入截屏', attachment_type=allure.attachment_type.PNG)
            sleep(3)
            self.click(self.submit)
        self.click(self.shipping_radio)
        self.click(self.payment_radio)
        sleep(3)
        self.click(self.submit_order)
        allure.attach(self.screenshots_png(), '提交订单页面截屏', attachment_type=allure.attachment_type.PNG)